package analysis.bean.key;

import analysis.bean.BrowserDimension;
import analysis.bean.Unit;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class StatsUser extends StatsUnit {
    public StatsCommon statsCommon;
    public BrowserDimension browserDimension;

    public StatsCommon getStatsCommon() {
        return statsCommon;
    }

    public void setStatsCommon(StatsCommon statsCommon) {
        this.statsCommon = statsCommon;
    }

    public BrowserDimension getBrowserDimension() {
        return browserDimension;
    }

    public void setBrowserDimension(BrowserDimension browserDimension) {
        this.browserDimension = browserDimension;
    }

    @Override
    public int compareTo(Unit o){
        StatsUser other = (StatsUser)o;
        if(!this.statsCommon.equals(other.statsCommon))
        {
            return this.statsCommon.compareTo(other.statsCommon);
        }else
        {
            if(!this.browserDimension.equals(other.browserDimension))
                return this.browserDimension.compareTo(other.browserDimension);
            else
            {
                return 0;
            }
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        this.statsCommon.write(dataOutput);
        this.browserDimension.write(dataOutput);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.statsCommon.readFields(dataInput);
        this.browserDimension.readFields(dataInput);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StatsUser statsUser = (StatsUser) o;
        return Objects.equals(statsCommon, statsUser.statsCommon) &&
                Objects.equals(browserDimension, statsUser.browserDimension);
    }

    @Override
    public int hashCode() {

        return Objects.hash(statsCommon, browserDimension);
    }
}
